
{extend name='public/window' /}

{block name="content"}

<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="form">

               <div class="layui-tab-item layui-show">

                        <div class="layui-form-item">
                            <label class="layui-form-label">资讯分类：</label>
                            <div class="layui-input-block">
                                <select name="cate_id" >
                                    <option value="0">请选资讯分类</option>
                                    {$cate|make_option='','title_show','id'}
                                </select>
                            </div>

                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">资讯标题：</label>
                            <div class="layui-input-block input-custom-width" style="">
                                <input type="text" name="title" value="" placeholder="请输入资讯标题" lay-verify="required" lay-vertype="tips" lay-reqtext="请输入资讯标题" autocomplete="off" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">关键词：</label>
                            <div class="layui-input-block input-custom-width" style="">
                                <input type="text" name="keywords" value="" placeholder="请输入关键词" lay-verify="required" lay-vertype="tips" lay-reqtext="请输入关键词" autocomplete="off" class="layui-input ">
                                <p class="help-block">关键词以英文逗号隔开！！！</p>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">摘要简述：</label>
                            <div class="layui-input-block input-custom-width" style="">
                                <textarea name="description" placeholder="" lay-verify=""  autocomplete="off" class="layui-textarea"></textarea>
                                <p class="help-block">简要描述</p>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">封面图：</label>
                            <div class="layui-input-inline">
                                <input name="img_url" lay-verify="required" lay-verType="tips" lay-reqText="" id="path_" placeholder="" value="" readonly class="layui-input">
                            </div>
                            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                <button type="button" class="layui-btn layui-btn-purples" id="LAY_up">
                                    <i class="layui-icon">&#xe67c;</i>上传图片
                                </button>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">是否热点：</label>
                            <div class="layui-input-inline input-custom-width">
                                <input type="radio" name="is_show" value="1" title="是" lay-filter="">
                                <input type="radio" name="is_show" value="0" title="否" lay-filter="" checked>
                            </div>

                            <label class="layui-form-label">是否推荐：</label>
                            <div class="layui-input-inline input-custom-width">
                                <input type="radio" name="is_recommend" value="1" title="是" lay-filter=""  >
                                <input type="radio" name="is_recommend" value="2" title="否" lay-filter="" checked>
                            </div>

                        </div>

                       <div class="layui-form-item">
                           <label class="layui-form-label">是否置顶：</label>
                           <div class="layui-input-inline input-custom-width">
                               <input type="radio" name="is_top" value="1" title="是" lay-filter=""  >
                               <input type="radio" name="is_top" value="0" title="否" lay-filter="" checked>
                           </div>
                       </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">文章作者：</label>
                            <div class="layui-input-inline input-custom-width">
                                <input type="text" name="author" value="{$_info.username}" placeholder="请输入作者"  autocomplete="off" class="layui-input ">
                            </div>
                            <label class="layui-form-label">点击量：</label>
                            <div class="layui-input-inline input-custom-width">
                                <input type="number" min="0" name="hits" value="0" placeholder=""  autocomplete="off" class="layui-input ">
                            </div>
                        </div>

                        <textarea name="content" placeholder="" style="max-width: 90%" id="content"  lay-verify="required"></textarea>
                        {if isset($info.id)}
                        {:build_ueditor(['name'=>'content','h'=>300,'content'=>$info['content']])}
                        {else /}
                        {:build_ueditor(['name'=>'content','h'=>300])}
                        {/if}

                        {if isset($info.id)}
                        <input type="hidden" name="id" value="{$info.id}">
                        {/if}
                    </div>
                <div class="layui-form-item layui-layout-admin " style="width: 100%">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0px;text-align: center;">
                            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="add">提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script>
    layui.use(['element', 'form', 'jquery','lucky','upload','laydate','rate','colorpicker'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var upload = layui.upload;
        var laydate = layui.laydate;
        var rate=layui.rate;
        var colorpicker=layui.colorpicker;


        //表单赋值
        var info = {:json_encode($info)};
        form.val("form",info);

        //表单赋值
        colorpicker.render({
            elem: '#test-form'
            ,color: '#1c97f5'
            ,done: function(color){
                $('#test-form-input').val(color);
            }
        });

        rate.render({
            elem: '#test7'
            ,length: 5
            ,setText: function(value){
                $("#tt").val(value);
            },
            value:info.range
        });

        //图片上传
        upload.render({
            elem:'#LAY_up'
            ,url: "{:url('Common/UpArticlePic')}" //图片上传地址
            ,accept: 'images' //
            ,acceptMime: 'image/*'
            ,size: 1024*12
            ,before:function (res) {
                loading = layer.load(2, {
                    shade: [0.2, '#000'] //0.2透明度的白色背景
                });
            }
            ,done: function(data){
                layer.close(loading);
                if (data.code==1){
                    layer.msg(data.msg, {icon: 1, time: 1000},function () {
                        $("#path_").val(data.data.dir);
                    });
                } else {
                    layer.msg(data.msg, {icon: 5, time: 1000});
                }
            }
            ,error:function (red) {
                layer.close(loading);
                layer.msg("网络错误", {icon: 5, time: 1500});
            }
        });

        /**
         * 鼠标显示
         */
        $('#path_').hover(function(){
            var img = "<img class='img_msg' src='"+$(this).val()+"' style='width:100%;max-height: 600px;' />";
            img_show = layer.tips(img, this,{
                tips:[2, 'rgba(41,41,41,.0)']
                ,area: ['12%']
            });
        },function(){
            layer.close(img_show);
        });



        form.on('submit(add)', function (data) {
            lucky.FormSubmit("{:url('upAndAdd')}",data.field,true);
            return false;
        });
    })
</script>

{/block}

